package com.eat.fish_service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.eat.fish_service.entity.Dao.IpAndPort;
import com.eat.fish_service.netty_client.NettyClient;
import com.eat.fish_service.service.IpAndPortService;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.boot.web.servlet.ServletComponentScan;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.transaction.annotation.EnableTransactionManagement;

import java.util.List;

//@SpringBootApplication
@SpringBootApplication(exclude= {DataSourceAutoConfiguration.class}) //去掉springboot 默认的数据源配置
@ComponentScan(basePackages = {"com.eat"})
@MapperScan("com.eat.fish_service.mapper")
@EnableTransactionManagement
@ServletComponentScan(basePackages = "com.eat.fish_service.filter")
public class FishServiceApplication implements CommandLineRunner {

    @Autowired
    private NettyClient nettyClient;

    @Autowired
    private IpAndPortService ipAndPortService;

    public static void main(String[] args) {
        ConfigurableApplicationContext context = SpringApplication.run(FishServiceApplication.class, args);

    }

    @Override
    public void run(String... args) throws Exception {
        List<IpAndPort> list = ipAndPortService.list(new QueryWrapper<IpAndPort>().eq("is_opened",1));
//        System.out.println(list);
        nettyClient.start(list);
    }
}
